class MyArray:
    def __init__(self, capacity):
        self.arr = [None] * capacity
        self.size = 0

    def insert(self, index, element):
        # 判断索引
        if index < 0 or index > self.size:
            raise Exception("超出数组实际元素范围")
        if self.size >= len(self.arr):
            self.resize()
        for i in range(self.size - 1, -1, -1):
            self.arr[i + 1] = self.arr[i]
        self.arr[index] = element
        self.size += 1

    def resize(self):
        arr_new = [None] * len(self.arr) * 2
        for i in range(self.size):
            arr_new[i] = self.arr[i]
        self.arr = arr_new

    def output(self):
        for i in range(self.size):
            print(self.arr[i])

    def remove(self, index):
        if index < 0 or index > self.size:
            raise Exception("超出数组实际元素范围")
        for i in range(index, self.size):
            self.arr[i] = self.arr[i + 1]
        self.size -= 1


if __name__ == '__main__':
    arr = MyArray(4)
    arr.insert(0, 1)
    arr.insert(0, 2)
    arr.insert(0, 3)
    arr.insert(0, 4)
    arr.insert(0, 5)
    arr.output()
    print('--------------------')
    arr.remove(1)
    arr.output()
